﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

using LowLevelGraphics;
using LowLevelGraphics.Filter;

namespace LowLevelGraphics.Filter.Colors
{
    public class Solarize : BaseImageFilter
    {
        public Solarize()
        {
        }

        internal Solarize(Solarize _pixelConstraints)
        {
        }

        public override UnsafeBitmap Execute(UnsafeBitmap image)
        {
            int width = image.Width;
            int height = image.Height;
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    Color pix = image.GetPixel(x, y);
                    int red = pix.R;
                    if (red <= 127)
                    {
                        red = 255 - red;
                    }
                    int green = pix.G;
                    if (green <= 127)
                    {
                        green = 255 - green;
                    }
                    int blue = pix.B;
                    if (blue <= 127)
                    {
                        blue = 255 - blue;
                    }
                    image.SetPixel(x, y, Color.FromArgb(red, green, blue));
                }
            }
            return image;
        }

        public override object Clone()
        {
            return new Solarize(this);
        }
    }
}
